package com.diyizu.controller.impl;

import com.diyizu.domain.Student;
import com.diyizu.excle.ImportExcel;
import com.diyizu.factory.Factory;
import com.diyizu.service.IStudentInfoService;
import com.diyizu.service.impl.StudentInfoServiceImpl;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class BayExcle {
    Scanner sc = new Scanner(System.in);
    IStudentInfoService studentService = Factory.getStudentInfoService();
    public void bayExcle(){
        System.out.println("请输入需要导入文件的路径");
        String url = sc.next();
        File file = new File(url);
        try {
            List<String[]> strings = ImportExcel.readExcel(file);
            for (String[] string : strings) {
                Student student = new Student();
                student.setSid(string[1]);
                student.setName(string[2]);
                student.setSex(string[3]);
                student.setAge(Integer.parseInt(string[4]));
                student.setGrade(string[5]);
                student.setClasses(string[6]);
                student.setGroup(string[7]);
                student.setPhone(string[8]);
                student.setAddress(string[9]);
                studentService.addStudent(student);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
